#include<unistd.h>
#include<stdio.h>
#include<sys/types.h>
#include<string.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<errno.h>
#include<sys/wait.h>

#define LOG "log.txt"

int main()
{
  pid_t pid = fork();
  if(pid == 0)
  {
    int i = 5;
    while(i--)
    {
       printf("I am child process\n");
       sleep(1);
    }
    return 233;
  }
  else
  {
     int status = -1;
     pid_t p = waitpid(pid,&status,0);
     printf("child: %d exit code: %d exit signal: %d\n",p,(status>>8)&0xFF,status&0x7F);
  }
  //int fd = open(LOG, O_WRONLY | O_CREAT | O_TRUNC,0666); 
  //char s[] = {"hello Alpaca\n"};
  //write(fd,s,strlen(s));
  //close(fd);
  return 0;
}
